/*************************************************************************
    > File Name: client.cpp
    > Author: Lancer
    > Mail: 18826075768@163.com
************************************************************************/

#include <iostream>
#include <stdlib.h>
#include <pthread.h>
#include <string.h>
#include <string>
#include <unistd.h>

using namespace std;

void* tfnl(void* arg){
    sleep(5);
    cout << "the thread!" << endl;
    return NULL;
}

int main(){
    int ret;
    pthread_t tid;
    pthread_attr_t attr;
    ret = pthread_attr_init(&attr);
    if(ret){
        cout << "can't init attr " << strerror(ret) <<endl;
        return ret;
    }

    ret = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
    if(ret){
        cout << "can't set attr " << strerror(ret) <<endl;
        return ret;
    }

    ret = pthread_create(&tid, &attr, tfnl, NULL);
    if(ret){
        cout << "can't create thread " << strerror(ret) <<endl;
        return ret;
    }

    ret = pthread_join(tid, NULL);
    if(ret){
        cout << "thread has been detached " <<endl;
        return ret;
    }
    return 0;
}